﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class Control
    {
        static Control instance;

        List<Form> formStack;
        Form currentForm;

        DBConnection dbconn;

        private Control(Form caller)
        {
            dbconn = new DBConnection();
            formStack = new List<Form>();
            currentForm = caller;
        }

        public static Control getInstance(Form caller = null)
        {
            if (instance != null)
                return instance;

            return instance = new Control(caller);
        }

        public void OpenDatabaseConnection()
        {
            dbconn.OpenDatabaseConnection();
        }

        public bool IsDBConnectionOpen()
        {
            return dbconn.IsConnectionOpen();
        }

        public System.Data.Odbc.OdbcDataReader ExecuteQuery(String connStr)
        {
            return dbconn.ExecuteQuery(connStr);
        }

        public int ExecuteStmt(String connStr)
        {
            return dbconn.ExecuteStmt(connStr);
        }

        public void SwitchWindow(Form from, Form to)
        {
            formStack.Add(from);
            from.Hide();
            to.Show();
            currentForm = to;
        }

        public void CloseWindow(Form from)
        {
            Form to = formStack.Last();
            formStack.Remove(formStack.Last());
            // from.Close();
            to.Show();
            to.Activate();
        }
    }
}
